libostree: Add g_autoptr() support for the public types
authorKrzesimir Nowak <krzesimir@kinvolk.io>
Thu, 12 May 2016 12:42:26 +0000 (14:42 +0200)
committerAtomic Bot <atomic-devel@projectatomic.io>
Tue, 17 May 2016 21:13:19 +0000 (21:13 +0000)
To avoid breaking the ostree users we hide the autoptr setup behind an
OSTREE_WITH_AUTOCLEANUPS variable. The variable is set to 0 by
default, so users that want to start using them, have to define the
variable themselves to 1.

Probably after some transition period, the variable will be set 1 by
default.

This is conditional on GLib >= 2.44.0 being available. It does not
bump ostree's dependency on GLib.

Closes: #295
Approved by: cgwalters

Makefile-libostree.am
src/libostree/ostree-autocleanups.h [new file with mode: 0644]
src/libostree/ostree.h

index a619cbcfbdbe0a4b88b085c3d0c25c7c10b557fe..700d372fd46349547cb8a299d86dbcbcba0e30a0 100644 (file)
@@ -128,6 +128,7 @@ libostree_1_la_SOURCES = \
        src/libostree/ostree-gpg-verifier.h \
        src/libostree/ostree-gpg-verify-result.c \
        src/libostree/ostree-gpg-verify-result-private.h \
+       src/libostree/ostree-autocleanups.h \
        $(NULL)
 if USE_LIBARCHIVE
 libostree_1_la_SOURCES += src/libostree/ostree-libarchive-input-stream.h \
diff --git a/src/libostree/ostree-autocleanups.h b/src/libostree/ostree-autocleanups.h
new file mode 100644 (file)
index 0000000..d04ba9a
--- /dev/null
@@ -0,0 +1,65 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2016 Endless Mobile, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Krzesimir Nowak <krzesimir@kinvolk.io>
+ */
+
+#pragma once
+
+#include <ostree.h>
+
+G_BEGIN_DECLS
+
+#ifndef OSTREE_WITH_AUTOCLEANUPS
+#define OSTREE_WITH_AUTOCLEANUPS 0
+#endif
+
+#if OSTREE_WITH_AUTOCLEANUPS && GLIB_CHECK_VERSION(2, 44, 0)
+
+/*
+ * The following types have no specific clear/free/unref functions, so
+ * they can be used as the stack-allocated variables or as the
+ * g_autofree heap-allocated variables.
+ *
+ * OstreeRepoTransactionStats
+ * OstreeRepoImportArchiveOptions
+ * OstreeRepoExportArchiveOptions
+ * OstreeRepoCheckoutOptions
+ */
+
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (OstreeDiffItem, ostree_diff_item_unref)
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (OstreeRepoCommitModifier, ostree_repo_commit_modifier_unref)
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (OstreeRepoDevInoCache, ostree_repo_devino_cache_unref)
+
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (OstreeAsyncProgress, g_object_unref)
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (OstreeBootconfigParser, g_object_unref)
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (OstreeDeployment, g_object_unref)
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (OstreeGpgVerifyResult, g_object_unref)
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (OstreeMutableTree, g_object_unref)
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (OstreeRepo, g_object_unref)
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (OstreeRepoFile, g_object_unref)
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (OstreeSePolicy, g_object_unref)
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (OstreeSysroot, g_object_unref)
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (OstreeSysrootUpgrader, g_object_unref)
+
+G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC (OstreeRepoCommitTraverseIter, ostree_repo_commit_traverse_iter_clear)
+
+#endif
+
+G_END_DECLS
index f6bb6adbc4c1bba51d9a6e30f803f3133ef07022..9846a7e3a19af51b3c1a5dbde6628e776f825fb0 100644 (file)
@@ -31,3 +31,5 @@
 #include <ostree-bootconfig-parser.h>
 #include <ostree-diff.h>
 #include <ostree-gpg-verify-result.h>
+
+#include <ostree-autocleanups.h>